/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef VMCLASS_H_
#define VMCLASS_H_

#include <corelib/misc/hash_map>
#include "vmtypes.h"
#include "method.h"

namespace paper{

// an equality comparison for method
class method_equalkey
{

public:
    // equality comparator
    bool operator() ( const method * const &k1, const method * const &k2 ){
		return k1->meta_name() == k2->meta_name();
    }

};

// a hash class
class method_hash
{

public:
    // equality comparator
    corelib::uint32 operator() ( const method * const &k1 ){
		return hash( k1->meta_name() );
    }

protected:
    // ustring_hash
    corelib::ustring_hash hash;

};

class PAPER_API vm_class
{

public:
    // constructors
    vm_class( const corelib::ustring &name, corelib::uint32 cidx );
    virtual ~vm_class();
    // main interface
    corelib::pair<method*, bool> add_method( const corelib::ustring &name,
		const corelib::ustring &meta = "", corelib::uint32 nargs = 0 );
    bool get_method_idx( const corelib::ustring &meta_name, corelib::uint32 &idx );
    // getters
    method* get_method( corelib::uint32 idx );
    const corelib::ustring &name( void ) const;
    corelib::uint32 msize( void ) const;
    corelib::uint32 idx( void ) const;
    __register &single( void );

protected:
    // friends
    friend class vmachine;

    // types
    typedef corelib::hash_map<corelib::ustring, corelib::uint32, 
        corelib::ustring_hash> __attribute_map;
    typedef corelib::hash_map<const method*, corelib::uint32, 
        method_hash, method_equalkey> __method_map;

	// class core structure declaration
	typedef struct core;
	// internal core structure
	core *_core;

};

}; // namespace paper;

#endif // VMCLASS_H_
